﻿using Anke.SHManage.BLL;
using Anke.SHManage.Model;
using Anke.SHManage.Utility;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Anke.SHManage.Web.Areas.DD.Controllers
{
    public class DriverReportController : Controller
    {
        //
        // GET: /DD/DriverReport/





        #region 日报表页面相关

        public ActionResult DriverReportList()
        {
            //获取个人工号
            string selfWorkCode = UserOperateContext.Current.Session_UsrInfo.WorkCode;
            string LastModifier = UserOperateContext.Current.Session_UsrInfo.Name;
            //string selfWorkCode = "0317";
            //string LastModifier = "张三";
            this.ViewData["selfWorkCode"] = selfWorkCode;
            this.ViewData["LastModifier"] = LastModifier;
            UserOperateContext userOperateContext = new UserOperateContext();
            bool IsPermission = userOperateContext.getGongneng(1264);
            if (IsPermission)
            {
                return View();
            }
            else
            {
                return View("Error");
            }
        }

        public ActionResult DriverReportPick()
        {
            return View();
        }

        public ActionResult DriverReportPickMain()
        {
            return View();
        }

        public ActionResult DriverReportFill()
        {
            return View();
        }


        #region 取Fill页面的内容赋给 Fill页面

        /// <summary>
        /// 取车辆相关信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult getPickedAmbulanceLink()
        {
            string RowID = Request.Form["RowID"].ToString();


            try
            {
                D_DriverReport dr = new D_DriverReport();
                dr = new DriverReportBLL().GetAmbulanceLink(RowID);
                return Json(new { drinfo = dr }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {
                return this.Json("");
            }
        }

        /// <summary>
        /// 取收费相关信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult getPickedFeeLink()
        {
            string RowID = Request.Form["RowID"].ToString();

            try
            {
                D_DriverReport dr = new D_DriverReport();
                dr = new DriverReportBLL().GetFeeLink(RowID);
                return Json(new { FLinfo = dr }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {
                return this.Json("");
            }
        }
        /// <summary>
        /// 取收费发票相关信息
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public ActionResult getPickedFPLink()
        {
            string RowID = Request.Form["RowID"].ToString();
            try
            {
                D_DriverReport dr = new D_DriverReport();
                dr = new DriverReportBLL().GetFPLink(RowID);
                return Json(new { FPLinfo = dr }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {
                return this.Json("");
            }

        }
        /// <summary>
        /// 取医生，（如果出现多个医生，下拉框的可多选）
        /// </summary>
        /// <param name="RowID"></param>
        /// <returns></returns>
        public ActionResult getPickedDoctor(string RowID)
        {
            var list = new DriverReportBLL().Get_Doctor(RowID);
            return Json(list);
        }
        /// <summary>
        /// 取护士，（如果出现多个护士，下拉框的可多选）
        /// </summary>
        /// <param name="RowID"></param>
        /// <returns></returns>
        public ActionResult getPickedNurse(string RowID)
        {
            var list = new DriverReportBLL().Get_Nurse(RowID);
            return Json(list);
        }
        /// <summary>
        /// 取担架工，（如果出现多个担架工，下拉框的可多选）
        /// </summary>
        /// <param name="RowID"></param>
        /// <returns></returns>
        public ActionResult getPickedStretcher(string RowID)
        {
            var list = new DriverReportBLL().Get_Stretcher(RowID);
            return Json(list);
        }



        #endregion

        #region 获取勾选任务列表
        //获取勾选任务列表
        public ActionResult GetPickTask()
        {
            DateTime StartTime = Convert.ToDateTime(Request.Form["StartTime"]);
            DateTime EndTime = Convert.ToDateTime(Request.Form["EndTime"]);
            string Station = "";
            string Center = "";
            string ambulanceCode = Request.Form["ambulanceCode"].ToString();
            string DworkID = Request.Form["DworkID"].ToString();
            string eventDispatchCenterID = UserOperateContext.Current.Seesion_Dispatch_SubCenterID; //2020-11-22 zch 登录人所处急救中心

            int total = 0;
            var list = new DriverReportBLL().GetTaskInfoForRevisitPick(ref total, StartTime, EndTime, Center, Station, DworkID, ambulanceCode, eventDispatchCenterID);
            if (total > 0)
            {
                return Json(new { total = total, rows = list }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { total = 0, rows = "" }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
        }
        #endregion

        #region 获取日报主表内容


        //获取日报主表内容
        public ActionResult GetReportMain()
        {
            int rows = int.Parse(Request.Form["rows"]);
            int page = int.Parse(Request.Form["page"]);
            string DworkID = Convert.ToString(Request.Form["DworkID"]);
            int total = 0;
            var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.AgentWorkID == DworkID, p => p.ReportDate, false).Select(p => p.ToPOCO());

            // 生成规定格式的 json字符串发回 给异步对象
            Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
            {
                total = total,
                rows = list,
                footer = null
            };
            return Json(dgModel);

        }
        #endregion

        #region 保存 方法（勾选任务的保存）
        //保存
        public ActionResult SavaPickTask()
        {
            string EditRowID = Convert.ToString(Request.Form["EditRowID"]);//修改项的ID

            D_DriverReport rvinfo = new D_DriverReport();

            if (EditRowID.Length == 0) //如果修改项的ID为空
            {
                var tempID = System.Guid.NewGuid();
                rvinfo.ID = tempID;

                string tempAgentWorkID = Convert.ToString(Request.Form["AgentWorkID"]);
                rvinfo.AgentWorkID = tempAgentWorkID;

                DateTime tempReportDate = Convert.ToDateTime(Request.Form["ReportDate"]);
                rvinfo.ReportDate = tempReportDate;

                string tempAmbulanceCode = (Request.Form["AmbulanceCode"]).ToString();
                rvinfo.AmbulanceCode = tempAmbulanceCode;

                string tempAmbulanceNumber = (Request.Form["AmbulanceNumber"]).ToString();
                rvinfo.AmbulanceNumber = tempAmbulanceNumber;

                rvinfo.FillState = "已勾选任务，未填写日报";

                string tempBanCi = (Request.Form["BanCi"]).ToString();
                rvinfo.BanCi = tempBanCi;

                rvinfo.LastModifyTime = DateTime.Now;
                string tempLastModifier = (Request.Form["LastModifier"]).ToString();
                rvinfo.LastModifier = tempLastModifier;

                //add 2019-06-17 plq D_DriverReport主表添加WorkDate字段（工作日期）
                DateTime tempWorkDate = Convert.ToDateTime(Request.Form["WorkDate"]);
                rvinfo.WorkDate = tempWorkDate;

                string sDeliveryDetailInfo = Request.Form["sDeliveryDetailInfo"].ToString();
                List<D_DriverReportPick> relist = JsonHelper.GetJsonInfoBy<List<D_DriverReportPick>>(sDeliveryDetailInfo); //前台传来的从表数据

                //bool值是否不存在同数据
                bool ifnothaddate = true;

                // 如果新增的日期在主表中已经存在，就不能新插一条数据，用查出的ID 赋给主表ID，修改主表。
                DateTime ReportDate1 = Convert.ToDateTime(Request.Form["ReportDate"]);

                //写一个方法，传参数workID，进主表中看是否存在ReportDate 和 BanCi 和同AmbulanceNumber 都相等的数据。如果有，就
                List<D_DriverReport> irlist = new D_DriverReportBLL().GetListBy(p => p.AgentWorkID == tempAgentWorkID);
                //Guid tempHadID;
                for (int a = 0; a < irlist.Count; a++)
                {
                    if (tempReportDate == irlist[a].ReportDate && tempBanCi == irlist[a].BanCi && tempAmbulanceNumber == irlist[a].AmbulanceNumber)
                    {
                        //2016-6-22 zch 修改 不需要 判断是否存在相同车辆相同班次相同日期时不允许存入
                        ifnothaddate = true;

                    }
                }


                if (ifnothaddate)  //如果数据库中不存在同日期和同班次和同一辆车的数据
                {
                    int results = 0; int number = 0;
                    for (int i = 0; i < relist.Count; i++)
                    {
                        number++;
                        relist[i].ReportID = tempID;
                        results = (new D_DriverReportPickBLL().Add(relist[i]));  //存入D_DriverReportPick附表
                    }
                    //在子表中添加的个数
                    rvinfo.TaskTimes = number.ToString();

                    int zbresult = new D_DriverReportBLL().Add(rvinfo); //存入D_DriverReport主表
                    if (results > 0 && zbresult > 0)
                    {
                        return this.JsonResult(Utility.E_JsonResult.OK, "新增信息成功！", null, null);
                    }
                    else
                    {
                        return this.JsonResult(Utility.E_JsonResult.Error, "新增信息失败！", null, null);
                    }
                }
                else //如果数据库已存在同日期和同班次和同一辆车的数据
                {
                    return this.JsonResult(Utility.E_JsonResult.Error, "已存在相同日期相同班次日报表，无需重复添加！", null, null);
                }

            }
            //继续添加
            else //如果修改项的ID不为空
            {

                D_DriverReport secondrvinfo = new D_DriverReport();
                var guid = new Guid(EditRowID);
                secondrvinfo.ID = guid;
                string tempAgentWorkID = Convert.ToString(Request.Form["AgentWorkID"]);
                secondrvinfo.AgentWorkID = tempAgentWorkID;

                secondrvinfo.ReportDate = Convert.ToDateTime(Request.Form["ReportDate"]);
                secondrvinfo.AmbulanceCode = (Request.Form["AmbulanceCode"]).ToString();
                string tempAmbulanceNumber = (Request.Form["AmbulanceNumber"]).ToString();
                secondrvinfo.AmbulanceNumber = tempAmbulanceNumber;

                //add 2019-06-17 plq D_DriverReport主表添加WorkDate字段（工作日期）
                secondrvinfo.WorkDate = Convert.ToDateTime(Request.Form["WorkDate"]);
                D_DriverReport oldDr = new D_DriverReportBLL().GetModelWithOutTrace(p => p.ID == guid);
                if (oldDr != null) //2021-11-17 plq 继续添加时比较工作日期的最小值赋给WorkDate字段（工作日期）（以勾选任务中 生成任务时刻 最早的那天作为工作日期的值）    
                {
                    secondrvinfo.WorkDate = secondrvinfo.WorkDate <= oldDr.WorkDate ? secondrvinfo.WorkDate : oldDr.WorkDate;
                }

                string sDeliveryDetailInfo = Request.Form["sDeliveryDetailInfo"].ToString();
                List<D_DriverReportPick> relist = JsonHelper.GetJsonInfoBy<List<D_DriverReportPick>>(sDeliveryDetailInfo); //前台传来的从表数据

                int results = 0; int number = 0;
                for (int i = 0; i < relist.Count; i++)
                {
                    number++;
                    relist[i].ReportID = guid;
                    results = (new D_DriverReportPickBLL().Add(relist[i]));  //存入D_DriverReportPick附表
                }

                //需要添加方法，进子表中查出所有的ID 下的任务数的数量， 然后将number 的值和那个值相加，得出新的TaskTimes
                List<D_DriverReportPick> list = new D_DriverReportPickBLL().GetListBy(p => p.ReportID == guid);
                int oldnumber = list.Count();
                //int newnumber = oldnumber + number;
                int newnumber = oldnumber; //2021-11-17 plq debug：去子表中查询任务数时已经是继续添加任务Add存入附表后的数量，无需再加一次
                secondrvinfo.TaskTimes = newnumber.ToString(); //得出新的TaskTimes
                secondrvinfo.LastModifyTime = DateTime.Now;
                string tempLastModifier = (Request.Form["LastModifier"]).ToString();
                secondrvinfo.LastModifier = tempLastModifier;

                //修改D_DriverReport主表数据
                int zbresults = new D_DriverReportBLL().Modify(secondrvinfo, "ReportDate", "AmbulanceCode", "AmbulanceNumber", "AgentWorkID", "TaskTimes", "LastModifyTime", "LastModifier", "WorkDate");   //add 2019-06-17 plq D_DriverReport主表添加WorkDate字段（工作日期）
                if (results > 0 && zbresults > 0)
                {
                    return this.JsonResult(Utility.E_JsonResult.OK, "添加信息成功！", null, null);
                }
                else
                {
                    return this.JsonResult(Utility.E_JsonResult.Error, "添加信息失败！", null, null);
                }
            }
        }

        #endregion

        #region 获取出车任务的车辆，根据时间段和工号


        //获取出车任务的车辆，根据时间段和工号
        public ActionResult GetAmbulance(DateTime starttime, DateTime endtime, string DworkID)
        {
            try
            {
                string eventDispatchCenterID = UserOperateContext.Current.Seesion_Dispatch_SubCenterID; //2020-11-22 zch 登录人所处急救中心
                var list = new DriverReportBLL().Get_ActualCodeList(starttime, endtime, DworkID, eventDispatchCenterID);
                return Json(list);
            }
            catch (Exception)
            {
                return this.Json("");
            }
        }

        //public ActionResult GetStationAmbulance(DateTime starttime, DateTime endtime, string StationCode)
        //{
        //    try
        //    {
        //        var list = new DriverReportBLL().GetStationAmbulance(starttime, endtime, StationCode);
        //        return Json(list);
        //    }
        //    catch (Exception)
        //    {
        //        return this.Json("");
        //    }
        //}
        #endregion

        #region 日报表填写页面的保存

        //病历收费修改
        [HttpPost]
        public ActionResult SaveFillReport(D_DriverReport info)
        {
            info.FillState = "已填写日报";
            string templast = Convert.ToString(Request.Form["LastModifier"]);

            string DoctorName = Convert.ToString(Request.Form["zDoctorName"]);
            string NurseName = Convert.ToString(Request.Form["zNurseName"]);
            string Stretcher1Name = Convert.ToString(Request.Form["zStretcher1Name"]);

            info.DoctorName = DoctorName;
            info.NurseName = NurseName;
            info.Stretcher1Name = Stretcher1Name;

            info.LastModifier = templast;
            info.LastModifyTime = DateTime.Now;

            //int res = new D_DriverReportBLL().Modify(info, "FillState", "StationName", "StationCode", "CenterCode", "BanCi", "TaskTimes", "PRTimes", "EmptyTimes", "DriverName", "DoctorName",
            //    "NurseName", "Stretcher1Name", "OffDutyKM", "OnDutyKM", "DayKM", "RefuelLitre", "RefuelInvoiceNumber", "OffDutyDipstick", "OnDutyDipstick", "OilConsumption", "CarFee", "WaitingFee", "EmergencyFee", "DrugFeeTotal", "ExamineFeeTotal", "ConsumableFeeTotal",
            //     "MeasureFeeTotal", "baidufei", "ReceivableTotal", "PaidMoney", "PRFeeTotal", "UselessInvoiceString", "InvoiceNumberString", "Remark", "InvoiceNumberTotal", "LastModifier", "LastModifyTime", "AbnormalKM", "AbnormalOil", "AbnormalReson", "PRPrintTimes");
            int res = new D_DriverReportBLL().Modify(info, "FillState", "StationName", "StationCode", "CenterCode", "BanCi", "TaskTimes", "PRTimes", "EmptyTimes", "DriverName", "DoctorName",
                "NurseName", "Stretcher1Name", "OffDutyKM", "OnDutyKM", "DayKM", "RefuelLitre", "RefuelInvoiceNumber", "OffDutyDipstick", "OnDutyDipstick", "OilConsumption", "CarFee", "WaitingFee", "EmergencyFee", "DrugFeeTotal", "ExamineFeeTotal", "ConsumableFeeTotal",
                 "MeasureFeeTotal", "baidufei", "ReceivableTotal", "PaidMoney", "PRFeeTotal", "UselessInvoiceString", "InvoiceNumberString", "Remark", "InvoiceNumberTotal", "LastModifier", "LastModifyTime", "AbnormalKM", "AbnormalOil", "AbnormalReson", "PRPrintTimes", "PaidCarFee", "PaidPRFee", "EmptyInvoiceString", "NextMaintainKM", "RefuelMoney",
                 "XJMoney", "YBMoney", "MLMoney", "ZFBMoney", "WXMoney", "YLMoney");//2017-11-09 //2021-10-14 plq 适配医保上线，增加三明细字段 //2022-01-07 plq 增加支付宝、微信实收、银联收费明细字段
            if (res > 0)
                return Json(new { Result = "OK", Message = "日报信息提交成功！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);

            else
                return Json(new { Result = "Error", Message = "日报信息提交失败！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
        }


        #endregion

        #region   判断是否已填写过日报，如果已填写，将主表内容全部赋值给前台
        public ActionResult IFExistReportDate()
        {
            string RowID = Request.Form["RowID"].ToString();
            var guidID = new Guid(RowID);

            try
            {
                D_DriverReport dr = new D_DriverReport();
                dr = new D_DriverReportBLL().GetModelWithOutTrace(p => p.ID == guidID);
                return Json(new { drinfo = dr }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {
                return this.Json("");
            }

        }
        #endregion

        #region 撤销（即删除主表从表）
        public ActionResult deleteReportDate()
        {
            string rowID = Convert.ToString(Request.Form["deleteRowID"]);
            var ID = new Guid(rowID);
            D_DriverReport info = new D_DriverReport();

            info = new D_DriverReportBLL().GetModelWithOutTrace(p => p.ID == ID); //根据ID，取D_DriverReport

            int result = 0; int resultz = 0;

            if (info.ReportState != null && info.ReportState == "已勾选")
            {
                return this.JsonResult(Utility.E_JsonResult.Error, "已被分站长勾选，不能撤销！", null, null);

            }
            else
            {
                D_DriverReportPickBLL dedateDetail = new D_DriverReportPickBLL();
                result = dedateDetail.DelBy(p => p.ReportID == ID);
                D_DriverReportBLL dedate = new D_DriverReportBLL();

                resultz = dedate.DelBy(p => p.ID == ID);
                if (result > 0 || resultz > 0)//吴涛2016-09-29
                {
                    return this.JsonResult(Utility.E_JsonResult.OK, "撤销成功！", null, null);
                }
                else
                {
                    return this.JsonResult(Utility.E_JsonResult.Error, "撤销失败！", null, null);
                }
            }

        }

        #endregion

        #region 根据工号获取最新一次填写的日报的下班路码和下班油尺
        public ActionResult GetoffDuty()
        {
            string SAmbulance = Convert.ToString(Request.Form["SAmbulance"]);
            string ReportDate = Convert.ToString(Request.Form["ReportDate"]);

            try
            {
                D_DriverReport dr = new D_DriverReport();
                dr = new DriverReportBLL().GetoffDuty(SAmbulance, ReportDate);
                return Json(new { OffInfo = dr }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {
                return this.Json("");
            }

        }

        #endregion

        #endregion

        #region 非生产用车页面相关
        public ActionResult NonProductionReportFill()
        {
            return View();
        }

        [HttpPost]
        public ActionResult SaveFillReportNonP(D_DriverReport info)
        {
            var tempID = System.Guid.NewGuid();
            info.ID = tempID;

            info.FillState = "已填写日报";
            string templast = Convert.ToString(Request.Form["LastModifier"]);
            info.StationName = Convert.ToString(Request.Form["StationName"]);

            //string tempAgentWorkID = Convert.ToString(Request.Form["AgentWorkID"]);
            //info.AgentWorkID = tempAgentWorkID;

            //DateTime tempReportDate = Convert.ToDateTime(Request.Form["ReportDate"]);
            //info.ReportDate = tempReportDate;

            //string tempAmbulanceCode = (Request.Form["AmbulanceCode"]).ToString();
            //info.AmbulanceCode = tempAmbulanceCode;

            string tempAmbulanceNumber = (Request.Form["AmbulanceNumber"]).ToString();
            info.AmbulanceNumber = tempAmbulanceNumber;


            info.BanCi = "非生产用车";

            info.LastModifyTime = DateTime.Now;
            string tempLastModifier = (Request.Form["LastModifier"]).ToString();
            info.LastModifier = tempLastModifier;


            int res = new D_DriverReportBLL().Add(info); //存入D_DriverReport主表

            if (res > 0)
                return Json(new { Result = "OK", Message = "日报信息提交成功！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);

            else
                return Json(new { Result = "Error", Message = "日报信息提交失败！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult SaveFillReportNonPEdit(D_DriverReport secondrvinfo)
        {

            string tempAmbulanceNumber = (Request.Form["AmbulanceNumber"]).ToString();
            secondrvinfo.AmbulanceNumber = tempAmbulanceNumber;
            secondrvinfo.StationName = Convert.ToString(Request.Form["StationName"]);

            secondrvinfo.BanCi = "非生产用车";

            secondrvinfo.LastModifyTime = DateTime.Now;
            string tempLastModifier = (Request.Form["LastModifier"]).ToString();
            secondrvinfo.LastModifier = tempLastModifier;

            int zbresults = new D_DriverReportBLL().Modify(secondrvinfo, "ReportDate", "AmbulanceCode", "AmbulanceNumber", "AgentWorkID", "OffDutyKM", "OnDutyKM", "DayKM", "RefuelLitre", "RefuelInvoiceNumber", "OffDutyDipstick", "OnDutyDipstick",
                "OilConsumption", "Remark", "LastModifier", "LastModifyTime", "backup4", "Stretcher2WorkID", "Stretcher3WorkID");
            if (zbresults > 0)
            {
                return this.JsonResult(Utility.E_JsonResult.OK, "添加信息成功！", null, null);
            }
            else
            {
                return this.JsonResult(Utility.E_JsonResult.Error, "添加信息失败！", null, null);
            }

        }


        #endregion


        #region 分站长勾选页面相关

        //分站长勾选司机日报页面
        public ActionResult DriverReportStationPick()
        {
            UserOperateContext userOperateContext = new UserOperateContext();
            bool IsPermission = userOperateContext.getGongneng(1265);////判断登录人有无 分站日报勾选 权限 
            if (IsPermission)
            {
                //string selfWorkCode = UserOperateContext.Current.Session_UsrInfo.WorkCode;
                //string selfWorkCode = "0317";
                //根据工号取调度中取出所在分站的分站编码
                //string StationCode = new DriverReportBLL().GetStationByWorkID(selfWorkCode);
                //this.ViewData["StationCode"] = StationCode;

                P_User pUser = new P_User();
                pUser = UserOperateContext.Current.Session_UsrInfo;//获取登录人信息
                this.ViewData["PickworkID"] = pUser.WorkCode;
                this.ViewData["StationCode"] = pUser.P_Department.DispatchSationID;
                this.ViewData["CenterCode"] = pUser.P_Department.DispatchSubCenterID;

                return View();
            }
            else
            {
                return View("Error");
            }
        }
        //分站长查看日报主表明细页面
        public ActionResult DriverReportStationCheck()
        {
            return View();
        }



        #region 分站长勾选页面取 主表数据
        public ActionResult GetStationReportMain()
        {
            int rows = int.Parse(Request.Form["rows"]);
            int page = int.Parse(Request.Form["page"]);
            DateTime ReportDate = Convert.ToDateTime(Request.Form["ReportDate"]);
            DateTime ReportDateEnd = Convert.ToDateTime(Request.Form["ReportDateEnd"]);

            string PickStation = Convert.ToString(Request.Form["PickStation"]);
            string PickCenter = Convert.ToString(Request.Form["PickCenter"]);
            string PickWorkID = Convert.ToString(Request.Form["PickWorkID"]);

            //string StationCode = Convert.ToString(Request.Form["StationCode"]);


            int total = 0;

            E_StatisticsPermisson em = UserOperateContext.Current.getMaxPerForStatistics();
            string selfCenterID = UserOperateContext.Current.Session_UsrInfo.P_Department.DispatchSubCenterID != null ? UserOperateContext.Current.Session_UsrInfo.P_Department.DispatchSubCenterID : "";
            int centerid;
            if (selfCenterID.Length > 0)
            {
                centerid = int.Parse(selfCenterID);
            }
            else
            {
                centerid = -1;
            }

            string selfStationID = UserOperateContext.Current.Session_UsrInfo.P_Department.DispatchSationID != null ? UserOperateContext.Current.Session_UsrInfo.P_Department.DispatchSationID : ""; ;

            if (em == E_StatisticsPermisson.None)
                return Json("");

            else
            {
                if (em == E_StatisticsPermisson.ALL)
                {

                    //8中情况，分站和工号，分中心  填写情况   2016-3-14
                    if (PickStation.Length > 0 && PickWorkID.Length > 0 && PickCenter.Length > 0)  //111
                    {
                        int PickCenter1 = int.Parse(PickCenter);
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.ReportDate >= ReportDate && p.ReportDate <= ReportDateEnd
                            && p.CenterCode == PickCenter1 && p.StationCode == PickStation && p.AgentWorkID == PickWorkID && p.ReportState != "已勾选" && p.FillState == "已填写日报", p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                        {
                            total = total,
                            rows = list,
                            footer = null
                        };
                        return Json(dgModel);
                    }
                    if (PickStation.Length > 0 && PickWorkID.Length > 0 && PickCenter.Length == 0) //110
                    {
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.ReportDate >= ReportDate && p.ReportDate <= ReportDateEnd
                            && p.StationCode == PickStation && p.AgentWorkID == PickWorkID && p.ReportState != "已勾选" && p.FillState == "已填写日报", p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                        {
                            total = total,
                            rows = list,
                            footer = null
                        };
                        return Json(dgModel);
                    }
                    if (PickStation.Length > 0 && PickWorkID.Length == 0 && PickCenter.Length > 0)//101
                    {
                        int PickCenter1 = int.Parse(PickCenter);
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.ReportDate >= ReportDate
                              && p.CenterCode == PickCenter1 && p.ReportDate <= ReportDateEnd && p.StationCode == PickStation && p.ReportState != "已勾选" && p.FillState == "已填写日报", p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                        {
                            total = total,
                            rows = list,
                            footer = null
                        };
                        return Json(dgModel);
                    }
                    if (PickStation.Length > 0 && PickWorkID.Length == 0 && PickCenter.Length == 0) //100
                    {
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.ReportDate >= ReportDate
                            && p.ReportDate <= ReportDateEnd && p.StationCode == PickStation && p.ReportState != "已勾选" && p.FillState == "已填写日报", p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                        {
                            total = total,
                            rows = list,
                            footer = null
                        };
                        return Json(dgModel);
                    }
                    if (PickStation.Length == 0 && PickWorkID.Length > 0 && PickCenter.Length > 0) //011
                    {
                        int PickCenter1 = int.Parse(PickCenter);
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.ReportDate >= ReportDate
                               && p.CenterCode == PickCenter1 && p.ReportDate <= ReportDateEnd && p.AgentWorkID == PickWorkID && p.ReportState != "已勾选" && p.FillState == "已填写日报", p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                        {
                            total = total,
                            rows = list,
                            footer = null
                        };
                        return Json(dgModel);
                    }
                    if (PickStation.Length == 0 && PickWorkID.Length > 0 && PickCenter.Length == 0) //010
                    {
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.ReportDate >= ReportDate
                             && p.ReportDate <= ReportDateEnd && p.AgentWorkID == PickWorkID && p.ReportState != "已勾选" && p.FillState == "已填写日报", p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                        {
                            total = total,
                            rows = list,
                            footer = null
                        };
                        return Json(dgModel);
                    }
                    if (PickStation.Length == 0 && PickWorkID.Length == 0 && PickCenter.Length > 0) //001
                    {
                        int PickCenter1 = int.Parse(PickCenter);
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.ReportDate >= ReportDate
                             && p.ReportDate <= ReportDateEnd && p.CenterCode == PickCenter1 && p.ReportState != "已勾选" && p.FillState == "已填写日报", p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                        {
                            total = total,
                            rows = list,
                            footer = null
                        };
                        return Json(dgModel);
                    }
                    else  //000
                    {
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.ReportDate >= ReportDate && p.ReportDate <= ReportDateEnd && p.ReportState != "已勾选" && p.FillState == "已填写日报", p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                        {
                            total = total,
                            rows = list,
                            footer = null
                        };
                        return Json(dgModel);
                    }
                }
                else if (em == E_StatisticsPermisson.CENTER)
                {
                    //4中情况，分站和工号  填写情况   2016-3-14
                    if (PickStation.Length > 0 && PickWorkID.Length > 0)
                    {
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.CenterCode == centerid && p.ReportDate >= ReportDate && p.ReportDate <= ReportDateEnd && p.StationCode == PickStation && p.AgentWorkID == PickWorkID && p.ReportState != "已勾选" && p.FillState == "已填写日报", p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                  {
                      total = total,
                      rows = list,
                      footer = null
                  };
                        return Json(dgModel);
                    }
                    if (PickStation.Length > 0 && PickWorkID.Length == 0)
                    {
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.CenterCode == centerid && p.ReportDate >= ReportDate && p.ReportDate <= ReportDateEnd && p.StationCode == PickStation && p.ReportState != "已勾选" && p.FillState == "已填写日报", p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                  {
                      total = total,
                      rows = list,
                      footer = null
                  };
                        return Json(dgModel);
                    }
                    if (PickStation.Length == 0 && PickWorkID.Length > 0)
                    {
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.CenterCode == centerid && p.ReportDate >= ReportDate && p.ReportDate <= ReportDateEnd && p.AgentWorkID == PickWorkID && p.ReportState != "已勾选" && p.FillState == "已填写日报", p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                  {
                      total = total,
                      rows = list,
                      footer = null
                  };
                        return Json(dgModel);
                    }
                    else
                    {
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.CenterCode == centerid && p.ReportDate >= ReportDate && p.ReportDate <= ReportDateEnd && p.ReportDate <= ReportDateEnd && p.ReportState != "已勾选" && p.FillState == "已填写日报", p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                  {
                      total = total,
                      rows = list,
                      footer = null
                  };
                        return Json(dgModel);
                    }


                }
                else if (em == E_StatisticsPermisson.STATION)
                {
                    var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.StationCode == selfStationID && p.ReportDate >= ReportDate && p.ReportDate <= ReportDateEnd && p.AgentWorkID == PickWorkID && p.ReportState != "已勾选" && p.FillState == "已填写日报", p => p.ReportDate, false).Select(p => p.ToPOCO());
                    Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                    {
                        total = total,
                        rows = list,
                        footer = null
                    };
                    return Json(dgModel);
                }
                else
                {
                    return Json("");
                }
            }
            // 生成规定格式的 json字符串发回 给异步对象
        }
        #endregion

        //分站长已勾选的,并且backup2的日期,backup2为分站长勾选日期  backup1 为当时勾选的人的工号
        public ActionResult GetStationReportPicked()
        {
            int rows = int.Parse(Request.Form["rows"]);
            int page = int.Parse(Request.Form["page"]);
            DateTime PickDate = Convert.ToDateTime(Request.Form["PickDate"]);
            string pickcenter = Convert.ToString(Request.Form["PickedCenter"]);
            string pickstation = Convert.ToString(Request.Form["PickedStation"]);
            int total = 0;

            E_StatisticsPermisson em = UserOperateContext.Current.getMaxPerForStatistics();

            string PickWorkID = UserOperateContext.Current.Session_UsrInfo.WorkCode;   //登录人工号
            string selfCenterID = UserOperateContext.Current.Session_UsrInfo.P_Department.DispatchSubCenterID != null ? UserOperateContext.Current.Session_UsrInfo.P_Department.DispatchSubCenterID : "";
            int centerid;
            if (selfCenterID.Length > 0)
            {
                centerid = int.Parse(selfCenterID);
            }
            else
            {
                centerid = -1;
            }

            string selfStationID = UserOperateContext.Current.Session_UsrInfo.P_Department.DispatchSationID != null ? UserOperateContext.Current.Session_UsrInfo.P_Department.DispatchSationID : ""; ;


            if (em == E_StatisticsPermisson.None)
                return Json("");

            else
            {
                if (em == E_StatisticsPermisson.ALL)
                {
                    //四中情况
                    if (pickcenter.Length > 0 && pickstation.Length > 0)
                    {
                        int pickcenter1 = int.Parse(pickcenter);
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.backup2 == PickDate && p.ReportState == "已勾选" && p.CenterCode == pickcenter1 && p.StationCode == pickstation,
                            p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                        {
                            total = total,
                            rows = list,
                            footer = null
                        };
                        return Json(dgModel);

                    }
                    if (pickcenter.Length > 0 && pickstation.Length == 0)
                    {
                        int pickcenter1 = int.Parse(pickcenter);
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.backup2 == PickDate && p.ReportState == "已勾选" && p.CenterCode == pickcenter1,
                            p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                        {
                            total = total,
                            rows = list,
                            footer = null
                        };
                        return Json(dgModel);

                    }

                    if (pickcenter.Length == 0 && pickstation.Length > 0)
                    {
                        int pickcenter1 = int.Parse(pickcenter);
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.backup2 == PickDate && p.ReportState == "已勾选" && p.StationCode == pickstation,
                            p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                        {
                            total = total,
                            rows = list,
                            footer = null
                        };
                        return Json(dgModel);

                    }
                    else
                    {
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.backup2 == PickDate && p.ReportState == "已勾选",
                            p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                        {
                            total = total,
                            rows = list,
                            footer = null
                        };
                        return Json(dgModel);

                    }
                }
                else if (em == E_StatisticsPermisson.CENTER)
                {
                    if (pickstation.Length > 0)
                    {
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.CenterCode == centerid && p.StationCode == pickstation && p.backup1 == PickWorkID && p.backup2 == PickDate && p.ReportState == "已勾选"
                            , p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                        {
                            total = total,
                            rows = list,
                            footer = null
                        };
                        return Json(dgModel);
                    }
                    else
                    {
                        var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.CenterCode == centerid && p.backup1 == PickWorkID && p.backup2 == PickDate && p.ReportState == "已勾选", p => p.ReportDate, false).Select(p => p.ToPOCO());
                        Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                        {
                            total = total,
                            rows = list,
                            footer = null
                        };
                        return Json(dgModel);
                    }
                }
                else if (em == E_StatisticsPermisson.STATION)
                {
                    var list = new D_DriverReportBLL().GetPagedList(page, rows, ref total, p => p.StationCode == selfStationID && p.backup1 == PickWorkID && p.backup2 == PickDate && p.ReportState == "已勾选", p => p.ReportDate, false).Select(p => p.ToPOCO());
                    Model.EasyUIModel.DataGridModel dgModel = new Model.EasyUIModel.DataGridModel()
                    {
                        total = total,
                        rows = list,
                        footer = null
                    };
                    return Json(dgModel);
                }

                else
                {
                    return Json("");
                }
            }



        }
        // 生成规定格式的 json字符串发回 给异步对象

        //分站提交勾选
        [HttpPost]
        public ActionResult SavaPickStationReport()
        {

            string PickWorkID = UserOperateContext.Current.Session_UsrInfo.WorkCode;//获取勾选分站提交的人的工号(到底谁来勾选分站车辆的)

            string sDeliveryDetailInfo = Request.Form["sDeliveryDetailInfo"].ToString();
            List<D_DriverReport> relist = JsonHelper.GetJsonInfoBy<List<D_DriverReport>>(sDeliveryDetailInfo); //前台传来的从表数据

            int results = 0;
            for (int i = 0; i < relist.Count; i++)
            {
                relist[i].backup2 = DateTime.Now;
                relist[i].backup1 = PickWorkID;
                results = new D_DriverReportBLL().Modify(relist[i], "ReportState", "backup2", "backup1");  //存入D_DriverReport附表
            }

            if (results > 0)
            {
                return this.JsonResult(Utility.E_JsonResult.OK, "添加信息成功！", null, null);
            }
            else
            {
                return this.JsonResult(Utility.E_JsonResult.Error, "添加信息失败！", null, null);
            }

        }


        //2019-06-13 plq 撤销已勾选
        [HttpPost]
        public ActionResult DeletePickedReport()
        {
            string PickWorkID = UserOperateContext.Current.Session_UsrInfo.WorkCode;//获取勾选分站提交的人的工号(到底谁来勾选分站车辆的)
            string sDeliveryDetailInfo = Request.Form["sDeliveryDetailInfo"].ToString();
            List<D_DriverReport> relist = JsonHelper.GetJsonInfoBy<List<D_DriverReport>>(sDeliveryDetailInfo); //前台传来的从表数据

            int results = 0;
            for (int i = 0; i < relist.Count; i++)
            {
                relist[i].backup2 = DateTime.Now;
                relist[i].backup1 = PickWorkID;
                results = new D_DriverReportBLL().Modify(relist[i], "ReportState", "backup2", "backup1");  //修改D_DriverReport附表实体
            }

            if (results > 0)
            {
                return this.JsonResult(Utility.E_JsonResult.OK, "撤销成功！", null, null);
            }
            else
            {
                return this.JsonResult(Utility.E_JsonResult.Error, "撤销失败！", null, null);
            }

        }

        #endregion


        #region 解款相关 2018-06-04 zch add    //2018-12-06 zch 修改
        public ActionResult PayInView()
        {
            return View();
        }

        [HttpPost]
        public ActionResult GetPayByCode()  //获取解款内容弹层页初始加载信息
        {
            //判断是否提交过解款内容，若有，则从D_DriverReprotPayIn取，否则，从D_DriverReport中取

            string RowID = (Request.Form["RowID"]).ToString();
            var guid = new Guid(RowID);

            D_DriverReport drInfo = new D_DriverReport();
            D_DriverReportBLL drBLL = new D_DriverReportBLL();
            drInfo = drBLL.GetModelWithOutTrace(p => p.ID == guid);

            D_DriverReprotPayInBLL piBll = new D_DriverReprotPayInBLL();
            D_DriverReprotPayIn pInfo = null;
            pInfo = piBll.GetModelWithOutTrace(p => p.ID == guid);

            if (pInfo != null)
            {
                bool isTimeOut = false;
                //  dInfo.AmountPayable = drInfo.PaidMoney;  //应缴金额从主表获取
                if (pInfo.PayInDate.Value.AddDays(15) < DateTime.Now)
                {
                    isTimeOut = true;
                }
                return Json(new { Result = "OK", Info = pInfo, timeOut = isTimeOut }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
            }
            else
                return Json(new { Result = "Error", Info = drInfo }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
        }

        [HttpPost]
        public ActionResult SubmitPay() //解款内容编辑页提交
        {
            //判断是否存在，如果存在就更新、不存在就插入

            string RowID = (Request.Form["RowID"]).ToString();
            DateTime PayTime = Convert.ToDateTime(Request.Form["PayTime"]);
            string PayNumber = (Request.Form["PayNumber"]).ToString();
            string PayPerson = (Request.Form["PayPerson"]).ToString();
            string PayRemark = (Request.Form["PayRemark"]).ToString();

            double PayMoney = Convert.ToDouble(Request.Form["PayMoney"]);
            double UnpaidMoney = Convert.ToDouble(Request.Form["UnpaidMoney"]);
            double AmountPayable = Convert.ToDouble(Request.Form["AmountPayable"]);
            //add 2019-07-04 plq 凭证上交日期可为空（非必填项）
            string strSubmitTime = (Request.Form["SubmitTime"]).ToString();
            DateTime? SubmitTime;
            if (strSubmitTime == "")
            {
                SubmitTime = null;
            }
            else {
                SubmitTime = Convert.ToDateTime(Request.Form["SubmitTime"]); //add20190613 plq 凭证上交日期
            }
            var guid = new Guid(RowID);
            D_DriverReprotPayIn payInfo = new D_DriverReprotPayIn();
            payInfo.ID = guid;
            payInfo.PayInDate = PayTime;
            payInfo.PayInNumber = PayNumber;
            payInfo.PayInPerson = PayPerson;
            payInfo.Remark = PayRemark;
            payInfo.PaymentAmount = PayMoney;
            payInfo.UnPaidAmount = UnpaidMoney;
            payInfo.AmountPayable = AmountPayable;
            payInfo.SubmitDate = SubmitTime;//add20190613 plq 凭证上交日期

            D_DriverReprotPayInBLL piBll = new D_DriverReprotPayInBLL();
            D_DriverReprotPayIn Info2 = null;
            Info2 = piBll.GetModelWithOutTrace(p => p.ID == guid);
            int res = 0;
            if (Info2 != null) //有则更新
                res = piBll.Modify(payInfo, "PayInDate", "PayInNumber", "PayInPerson", "Remark", "PaymentAmount", "UnPaidAmount", "AmountPayable", "SubmitDate");
            else  //无则新增
            {
                D_DriverReport d = new D_DriverReport();
                D_DriverReportBLL drBLL = new D_DriverReportBLL();
                d.ID = payInfo.ID;
                d.FillPerson = "已解款";
                drBLL.Modify(d, "FillPerson");
                res = piBll.Add(payInfo); //新增实体
            }
            if (res > 0)
                return Json(new { Result = "OK", Message = "提交成功！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);

            else
                return Json(new { Result = "Error", Message = "提交失败！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
        }

        #endregion

        //分站长已勾选的 财务可审核 2018-06-04 zch
        [HttpPost]
        public ActionResult DRPickedCheck()
        {
            UserOperateContext userOperateContext = new UserOperateContext();
            bool Insert = userOperateContext.getGongneng(1312);////判断登录人有无财务审批权限 
            if (Insert)
            {
                string rowID = Convert.ToString(Request.Form["rowCheckId"]);
                var ID = new Guid(rowID);
                D_DriverReport info = new D_DriverReport();

                info = new D_DriverReportBLL().GetModelWithOutTrace(p => p.ID == ID); //根据ID，取D_DriverReport
                info.UnPickTask = "已审核";
                int result = 0;
                D_DriverReportBLL dedate = new D_DriverReportBLL();

                result = dedate.Modify(info, "UnPickTask");
                if (result >= 0)
                {
                    // return Json(new { Result = "OK", Message = "审核记录成功！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
                    return Json("");
                }
                else
                {
                    return Json(new { Result = "Error", Message = "审核记录失败！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);
                }
            }
            else
            {
                return Json(new { Result = "Error", Message = "对不起,您不具备审核权限！" }, "text/plain;charset=UTF-8", JsonRequestBehavior.AllowGet);

            }
        }

        #region 移动支付 add2022-01-13 plq 从闵行移植

        #region 财务银联对账审核
        //取自定义对账---取每次任务收费详细信息
        public ActionResult GetTaskChargeDetail()
        {
            UserOperateContext userOperateContext = new UserOperateContext();
            DateTime start = Convert.ToDateTime(Request.Form["StartTime"]);
            DateTime end = Convert.ToDateTime(Request.Form["EndTime"]);
            int center = -1;
            if (Request.Form["Center"].ToString() != "")
                center = Convert.ToInt32(Request.Form["Center"].ToString());
            string station = Request.Form["Station"].ToString();
            int ifcheck = Convert.ToInt32(Request.Form["IfCheck"]);
            string invoicenumber = Request.Form["InvoiceNumber"].ToString();
            string outtradeno = Request.Form["OutTradeNo"].ToString();
            string patientname = Request.Form["PatientName"].ToString();
            int rows = Convert.ToInt32(Request.Form["rows"]);
            int page = Convert.ToInt32(Request.Form["page"]);
            List<TaskChargeDetailInfo> footList = new List<TaskChargeDetailInfo>();

            int total = 0;
            var list = new DriverReportBLL().GetTaskChargeDetail(rows, page, ref total, ref footList, start, end, center, station, ifcheck, invoicenumber, outtradeno, patientname);
            if (total > 0)
            {
                return Json(new { total = total, rows = list, footer = footList }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
            else
            {
                list = new string[] { };
                return Json(new { total = 0, rows = list, footer = footList }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
        }
        //获取分中心汇总对账明细
        public ActionResult GetCenterChargeCheck()
        {
            UserOperateContext userOperateContext = new UserOperateContext();
            DateTime start = Convert.ToDateTime(Request.Form["StartTime"]);
            DateTime end = Convert.ToDateTime(Request.Form["EndTime"]);

            int total = 0;
            var list = new DriverReportBLL().GetCenterChargeCheck(ref total, start, end);
            if (total > 0)
            {
                return Json(new { total = total, rows = list }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
            else
            {
                list = new string[] { };
                return Json(new { total = 0, rows = list }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
        }

        //获取分站汇总对账明细
        public ActionResult GetStationChargeCheck()
        {
            UserOperateContext userOperateContext = new UserOperateContext();
            DateTime start = Convert.ToDateTime(Request.Form["StartTime"]);
            DateTime end = Convert.ToDateTime(Request.Form["EndTime"]);
            string centerCode = Convert.ToString(Request.Form["CenterCode"]);

            int total = 0;
            var list = new DriverReportBLL().GetStationChargeCheck(ref total, start, end, centerCode);
            if (total > 0)
            {
                return Json(new { total = total, rows = list }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
            else
            {
                list = new string[] { };
                return Json(new { total = 0, rows = list }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
        }

        //获取分站任务流水对账
        public ActionResult GetTaskChargeCheck()
        {
            UserOperateContext userOperateContext = new UserOperateContext();
            DateTime start = Convert.ToDateTime(Request.Form["StartTime"]);
            DateTime end = Convert.ToDateTime(Request.Form["EndTime"]);
            string stationCode = Convert.ToString(Request.Form["Station"]);
            string ifCheck = Request.Form["ifCheck"];//20171219 yh
            int total = 0;
            List<TaskChargeDetailInfo> footList = new List<TaskChargeDetailInfo>();
            var list = new DriverReportBLL().GetTaskChargeCheck(ref total, ref footList, start, end, stationCode, ifCheck);
            if (total > 0)
            {
                return Json(new { total = total, rows = list, footer = footList }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
            else
            {
                list = new string[] { };
                return Json(new { total = 0, rows = list, footer = footList }, "appliction/json", JsonRequestBehavior.AllowGet);
            }
        }
        //财务批量审核
        [HttpPost]
        public ActionResult SavaBatchCheck()
        {
            string sDeliveryDetailInfo = Request.Form["sDeliveryDetailInfo"].ToString();
            List<TaskChargeDetailInfo> relist = JsonHelper.GetJsonInfoBy<List<TaskChargeDetailInfo>>(sDeliveryDetailInfo); //前台传来的从表数据
            int results = 0;
            for (int i = 0; i < relist.Count; i++)
            {
                results = new DriverReportBLL().UpdateChargeAccountCheck(relist[i].ID);
            }

            if (results > 0)
            {
                return this.JsonResult(Utility.E_JsonResult.OK, "审核成功！", null, null);
            }
            else
            {
                return this.JsonResult(Utility.E_JsonResult.Error, "审核失败！", null, null);
            }

        }

        //财务对账单个审核
        [HttpPost]
        public ActionResult SavaCheck()
        {
            string taskcode = Request.Form["taskcode"].ToString();
            int results = new DriverReportBLL().UpdateChargeAccountCheck(taskcode);

            if (results > 0)
            {
                return this.JsonResult(Utility.E_JsonResult.OK, "审核成功！", null, null);
            }
            else
            {
                return this.JsonResult(Utility.E_JsonResult.Error, "审核失败！", null, null);
            }

        }

        //财务对账单个撤销
        [HttpPost]
        public ActionResult CancelCheck()
        {
            string taskcode = Request.Form["taskcode"].ToString();
            int results = new DriverReportBLL().CancelChargeAccountCheck(taskcode);

            if (results > 0)
            {
                return this.JsonResult(Utility.E_JsonResult.OK, "撤销成功！", null, null);
            }
            else
            {
                return this.JsonResult(Utility.E_JsonResult.Error, "撤销失败！", null, null);
            }

        }
        #endregion

        #endregion

    }
}
